<script setup>
import { ref, defineProps, defineEmits } from 'vue';

const props = defineProps({
  label: String,
  required: Boolean
});

const emit = defineEmits(['validate']);

const value = ref(false);
const errorMessage = ref('');

const validate = () => {
  if (props.required && !value.value) {
    errorMessage.value = '必填项';
    emit('validate', false);
  } else {
    errorMessage.value = '';
    emit('validate', true);
  }
};
</script>


<template>
  <div>
    <input type="checkbox" v-model="value">{{ label }}
    <span>{{ errorMessage }}</span>
  </div>
</template>

